<template>
	<view class="content">
		<u-navbar title="黑名单" :border-bottom="false" back-icon-color="#ffffff" title-color="#fff" :background="{backgroundColor:'#2A2931'}"></u-navbar>
		<view class="list">
			<view class="item" v-for="(item,index) in blacklist">
				<view class="left">
					<u-avatar :src="HOSTURL + item.user_head"></u-avatar>
					<text class="name">{{item.user_name}}</text>
				</view>
				<view class="remove" @click="remove(item.user_id,index)">移除黑名单</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				HOSTURL:this.$HOSTURL,
				page:0,
				blacklist:[]
			}
		},
		onLoad() {
			this.getblacklist()
		},
		methods: {
			async getblacklist(){
				const { data: res } = await this.$Request({
					url:'api/user/blackList',
					data:{
						user_id: this.$store.state.userid,
						pagecount: 10,
						pagesize: 10,
						page: this.page
					}
				})
				this.blacklist = this.blacklist.concat(res.result)
			},
			async remove(uid,index){
				const { data: res } = await this.$Request({
					url: 'api/user/addBlackList',
					data:{
						to_user: uid,
						user_id: this.$store.state.userid
					}
				})
				if(res.code==200){
					this.blacklist.splice(index,1)
				}
			}
		},
		onReachBottom() {
			this.page++
			this.getblacklist()
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		min-height: 100vh;
		background-color: #2A2931;
		.list{
			.item{
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 20rpx 30rpx;
				.left{
					display: flex;
					align-items: center;
					color: #fff;
					image{
						width: 100rpx;
						height: 100rpx;
						border-radius: 50rpx;
					}
					.name{
						margin-left: 20rpx;
						font-weight: bold;
					}
				}
				.remove{
					color: rgb(213, 157, 81);
					font-size: 24rpx;
				}
			}
		}
	}
	
</style>
